<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="bootstrap.min.css">
    <style>
        #login {
            width: 400px;
            margin: 150px auto
        }

        #alert_info {
            margin: 2px;
            padding: 2px;
            text-align: center;
            margin-bottom: 10px;
            display: none
        }

        .panel-heading {
            text-align: center;
        }

        h1 {
            position: relative;
            left: 38%;
            top: 100px;
        }

        body {
            background: url(timg.jpg);
            overflow-x: hidden;
        }
    </style>
</head>

<body>
    <div class='container'>
        <h1>学生信息管理系统</h1>
        <div class='panel panel-primary' id='login'>
            <div class='panel-heading'>
                登录
            </div>
            <div class='panel-body'>
                <div class='form-group'>
                    <label for="username">用户名：</label>
                    <input type="text" name='username' class='form-control' id="username">
                </div>
                <div class='form-group'>
                    <label for="password">密码：</label>
                    <input type="password" name='password' class='form-control' id="password">
                </div>
                <div id='alert_info' class='alert alert-danger'>xxxxx</div>
                <div class="checke">
                    <label>
                        <input type="checkbox" id="checkbox"> 30天内免登陆
                    </label>
                </div>
                <a href="register.html">马上注册</a>
                <button id='btn1' class='btn btn-primary pull-right'>登录</button>
            </div>
        </div>
    </div>
    <script src="jquery.min.js"></script>
    <script src="cookie.js"></script>
    <script>
        $("#username").val(getCookie("username"));
        $("#password").val(getCookie("password"));
        $("#btn1").click(function () {
            $.ajax({
                url: "http://127.0.0.1/login",
                data: {
                    username: $("#username").val(),
                    password: $("#password").val()
                },
                success(data) {
                    if (data === "error") {
                        alert("用户名或密码错误");
                    } else {
                        sessionStorage.setItem("username", data);
                        location.href = "http://127.0.0.1/students.html"
                    }
                }
            })
            if ($("#checkbox")[0].checked === true) {
                setCookie("username", $("#username").val(), 30)
                setCookie("password", $("#password").val(), 30)
            }
        })
    </script>
</body>

</html>